home *** CD-ROM | disk | FTP | other *** search
- /*
- SplitOSDocs.rexx Macro
- Splits OS3.5 HTML manuals into manageable-sized chapters
- $VER: SplitOSDocs.rexx v1.00 (1 Nov 1999)
- ©Ron Goertz (goertz@earthlink.net)
- */
-
- options results
-
- BS = '08'x
- LF = '0a'x
- ChunkSize = 10000
- ManualName.0 = 'arexx'
- ManualName.1 = 'dos'
- ManualName.2 = 'harddisk'
- ManualName.3 = 'installation'
- ManualName.4 = 'workbench'
- DocName.0 = 'book-main.html'
- DocName.1 = 'book-index.html'
- DocName.2 = 'book-toc.html'
- DocName.3 = 'index.html'
- Header1 = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML EXPERIMENTAL 970324//EN">'LF'<HTML>'LF'<TITLE>'
- Header2 = '</TITLE>'LF'</HEAD>'LF'<BODY BGCOLOR="#ffffff">'
- Footer = '</BODY>'LF'</HTML>'
- SourcePath = ''
- DestPath = ''
-
- call addlib('rexxreqtools.library', 0, -30, 0)
- call addlib('rexxsupport.library', 0, -30, 0)
-
- address command 'REQUESTFILE >t:Path DRAWER "AmigaOS3.5:OS-Version3.5/AmigaOS 3.5 Manual" TITLE "Select the original document directory:" DRAWERSONLY NOICONS'
- call open('Temp', 't:Path');SourcePath = compress(readln('Temp'), '"');call close('Temp')
-
- address command 'REQUESTFILE >t:Path TITLE "Select destination directory:" DRAWERSONLY NOICONS'
- call open('Temp', 't:Path');DestPath = compress(readln('Temp'), '"');call close('Temp')
- address command 'delete t:Path quiet'
- if (rc == 5) | (SourcePath == '') | (DestPath == '') then exit
-
- call UpdateProgress('Copying root files and images...')
- address command 'copy "'SourcePath'#?.html" "'DestPath'" quiet'
- address command 'copy "'SourcePath'graphics" "'DestPath'graphics" all quiet'
-
- do Manual = 0 to 4
- call time(r)
- CurrentNode = ''
- FirstNode = ''
- Manual$ = 'Converting 'ManualName.Manual' manual...'LF
- SrcPath = SourcePath''ManualName.Manual'/'
- DstPath = DestPath''ManualName.Manual'/'
- call makedir(left(DstPath, length(DstPath) - 1))
-
- call UpdateProgress(Manual$' Copying root files and images...')
- address command 'copy "'SrcPath'#?.gif" "'DstPath'" quiet'
- address command 'copy "'SrcPath'menu.html" "'DstPath'" quiet'
- address command 'copy "'SrcPath'head.html" "'DstPath'" quiet'
-
- Category$ = Manual$' Standardizing document formats...'LF
-
- do i = 0 to 3
- call Standardize(DocName.i)
- end
-
- Category$ = Manual$' Splitting 'DocName.0'...'LF
- call open('Src', DstPath'-'DocName.0)
- do until EOF('Src')
- Ln = ReadLn('Src')
- if Ln == '<DIV>' then do
- ReturnPos = seek('Src', 0)
- NextLn = ReadLn('Src')
- call seek('Src', ReturnPos, 'B')
- if (Manual == 2) then do
- if pos('<H2 CLASS="Überschrift1">', NextLn) > 0 then NextLn = '<H1 CLASS="Titel">'
- end
- end
- else NextLn = ''
- if eof('Src') then leave
- select
- when Ln == '</BODY>' then do
- call writeln('Dst', Footer)
- call close('Dst')
- leave
- end
- when (pos('<H1 CLASS="Titel">', Ln) > 0) & (pos('</H', Ln) > 0) then do
- StartPos = pos('</A>', Ln)
- EndPos = pos('</H', Ln)
- NodeName = strip(substr(Ln, StartPos + 4, EndPos - StartPos - 4))
- call SetNode(NodeName)
- if pos('<A NAME=', Ln) > 0 then do
- KeyStart = pos('=', Ln, pos('<A NAME=', Ln) + 8) + 1
- KeyEnd = pos('"', Ln, KeyStart)
- Key = substr(Ln, KeyStart, KeyEnd - KeyStart)
- Name.Key = CurrentNode
- end
- end
- when (Ln == '<DIV>') & ((pos('<H1 CLASS="Titel">', NextLn) > 0) & (pos('</H', NextLn) == 0)) then do
- ReturnPos = seek('Src', 0)
- do forever
- TLn = readln('Src')
- if pos('</H', TLn) > 0 then leave
- end
- call seek('Src', ReturnPos, 'B')
- NodeName = left(TLn, pos('</H', TLn) - 1)
- call SetNode(NodeName)
- end
- when pos('<A NAME=', Ln) > 0 then do
- KeyStart = pos('=', Ln, pos('<A NAME=', Ln) + 8) + 1
- KeyEnd = pos('"', Ln, KeyStart)
- Key = substr(Ln, KeyStart, KeyEnd - KeyStart)
- Name.Key = CurrentNode
- end
- otherwise nop
- end
- if CurrentNode ~= '' then call writeln('Dst', Ln)
- end
- call Close('Src')
- address command 'delete "'DstPath'-'DocName.0'" quiet'
-
- do i = 1 to 2
- call UpdateProgress(Manual$' Updating 'DocName.i'...')
- call open('Src', DstPath'-'DocName.i)
- call open('Dst', DstPath''DocName.i, 'W')
- do until EOF('Src')
- Ln = ReadLn('Src')
- if eof('Src') then leave
- if pos('<A HREF="book-main.html#', Ln) > 0 then do
- Key = substr(Ln, pos('=', Ln, 25) + 1)
- Key = left(Key, pos('"', Key) - 1)
- Ln = ReplaceString('book-main.html', Name.Key, Ln)
- end
- call writeln('Dst', Ln)
- end
- call close('Dst')
- call close('Src')
- address command 'delete "'DstPath'-'DocName.i'" quiet'
- end
-
- call UpdateProgress(Manual$' Updating 'DocName.3'...')
- call open('Src', DstPath'-'DocName.3)
- call open('Dst', DstPath''DocName.3, 'W')
- call writech('Dst', ReplaceString('book-main.html', FirstNode, readch('Src', 65535)))
- call close('Dst')
- call close('Src')
- address command 'delete "'DstPath'-'DocName.3'" quiet'
-
- Time.Manual = time(e)
- end
- writeln(stdout, '0c'x||'Done!')
- do i = 0 to 4
- writeln(stdout, 'It took 'trunc(Time.i / 60, 2)' minutes to convert the 'ManualName.i' manual.')
- end
- exit
-
- /***//******* ReplaceString Subroutine ***********/
- ReplaceString: PROCEDURE
- parse arg old, new, string
-
- StartPos = pos(old, string)
- do while StartPos > 0
- parse var string begin(old)end
- string = begin''new''end
- StartPos = pos(old, string)
- end
- return string
- /**/
-
- /***//******* SetNode Subroutine ***********/
- SetNode:
- if CurrentNode ~= '' then do
- call writeln('Dst', Footer)
- call close('Dst')
- end
- call UpdateProgress(Category$' 'NodeName)
- CurrentNode = translate(NodeName, xrange('a','z'), xrange('A', 'Z'))
- if words(CurrentNode) > 1 then do
- CurrentNode = substr(CurrentNode, max(1, max(pos('chapter', CurrentNode), pos('appendix', CurrentNode))))
- CurrentNode = compress(subword(CurrentNode, 1, 2))
- end
- CurrentNode = CurrentNode'.html'
- if FirstNode == '' then FirstNode = CurrentNode
- call open('Dst', DstPath''CurrentNode, 'W')
- call writeln('Dst', Header1''NodeName''Header2)
- return
- /**/
-
- /***//******* Standardize Subroutine ***********/
- Standardize:
- parse arg DocName
-
- call UpdateProgress(Category$' 'DocName)
- call writech(stdout, copies('.', trunc(word(statef(SrcPath''DocName), 2)/ChunkSize + 2)))
- call Open('Src', SrcPath''DocName)
- call Open('Dst', DstPath'-'DocName, 'W')
- do until eof('Src')
- call writech(stdout, BS' 'BS)
- call writech('Dst', translate(ReplaceString('0d'x||'0a'x, '0a'x, compress(readch('Src', ChunkSize), '09'x)), '0a'x, '0d'x))
- end
- call close('Dst')
- call close('Src')
-
- return 0
- /**/
-
- /***//******* UpdateProgress Subroutine ***********/
- UpdateProgress:
- parse arg Msg
- writech(stdout, '0c'x||Msg)
- return
- /**/
-
-